<template>
  <div class="mobile-config">
    <div v-for="(item, key) in rCom" :key="key">
      <component
        :is="item.components.name"
        :configObj="configObj"
        ref="childData"
        :configNme="item.configNme"
        :key="key"
        @getConfig="getConfig"
        :index="activeIndex"
        :num="item.num"
      ></component>
    </div>
    <rightBtn :activeIndex="activeIndex" :configObj="configObj"></rightBtn>
  </div>
</template>

<script>
import rightBtn from '../rightBtn/index.vue';
import toolCom from '../mobileConfigRight/index.js';
import { mapState, mapMutations, mapActions } from 'vuex';
export default {
  name: 'c_home_button',
  componentsName: 'home_button',
  components: {
    ...toolCom,
    rightBtn,
  },
  props: {
    activeIndex: {
      type: null,
    },
    num: {
      type: null,
    },
    index: {
      type: null,
    },
  },
  data() {
    return {
      configObj: {},
      rCom: [
        {
          components: toolCom.c_checked_tab,
          configNme: 'setUp',
        },
        {
          components: toolCom.c_input_item,
          configNme: 'buttonText',
        },
      ],
    };
  },
  computed: {
    ...mapState('mobildConfig', ['defaultArray']),
  },
  watch: {
    num: {
      handler(nVal, oVal) {
        this.configObj = this.defaultArray[nVal];
      },
      deep: true,
    },
    defaultArray: {
      handler(nVal, oVal) {
        this.configObj = this.defaultArray[this.num];
      },
      deep: true,
    },
  },
  mounted() {
    this.getConfig();
  },
  methods: {
    ...mapMutations(['setRightNavStatus']),
    ...mapActions(['saveFormData']),
    getConfig() {
      if (this.num !== undefined) {
        this.configObj = this.defaultArray[this.num];
      }
      this.configObj = this.configObj || {};
    },
  },
};
</script>

<style scoped>
.mobile-config {
  padding: 20px;
}
</style>
